package cn.mrlong.tools.util

import cn.mrlong.tools.bean.ImageRecord
import com.fasterxml.jackson.core.JsonProcessingException
import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper

/**
 * @author LeeWyatt
 */
object ImageRecordUtil {
    @JvmStatic
    fun convertToList(imageRecords: String?): List<ImageRecord> {
        if (imageRecords == null) {
            return ArrayList()
        }
        try {
            return ObjectMapper()
                    .readValue(imageRecords,
                            object : TypeReference<List<ImageRecord>>() {
                            })
        } catch (e: JsonProcessingException) {
            e.printStackTrace()
        }
        return ArrayList()
    }

    fun convertToString(list: List<ImageRecord?>?): String {
        try {
            return ObjectMapper().writeValueAsString(list)
        } catch (e: JsonProcessingException) {
            e.printStackTrace()
        }
        return ""
    }
}